package com.groupbuying.store.service.impl;

import com.groupbuying.store.connector.SysconfigFeign;
import com.groupbuying.store.constants.GeoHashConstants;
import com.groupbuying.store.utils.GeoHashUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

import com.groupbuying.store.dao.GeoShopInfoDao;
import com.groupbuying.store.domain.GeoShopInfoDO;
import com.groupbuying.store.service.GeoShopInfoService;



@Service
public class GeoShopInfoServiceImpl implements GeoShopInfoService {
	@Autowired
	private GeoShopInfoDao geoShopInfoDao;

	@Autowired
	private SysconfigFeign sysconfigFeign;
	
	@Override
	public GeoShopInfoDO get(String id){
		return geoShopInfoDao.get(id);
	}
	
	@Override
	public List<GeoShopInfoDO> list(Map<String, Object> map){
		return geoShopInfoDao.list(map);
	}
	
	@Override
	public int count(Map<String, Object> map){
		return geoShopInfoDao.count(map);
	}
	
	@Override
	public int save(GeoShopInfoDO geoShopInfo){
		return geoShopInfoDao.save(geoShopInfo);
	}
	
	@Override
	public int update(GeoShopInfoDO geoShopInfo){
		return geoShopInfoDao.update(geoShopInfo);
	}
	
	@Override
	public int remove(String id){
		return geoShopInfoDao.remove(id);
	}
	
	@Override
	public int batchRemove(String[] ids){
		return geoShopInfoDao.batchRemove(ids);
	}

    @Override
    public void saveGeoShopInfo(String shopId, BigDecimal latitude, BigDecimal longitude) {

		Double lat = latitude.doubleValue();
		Double lgt = longitude.doubleValue();

		GeoShopInfoDO geoShopInfo = new GeoShopInfoDO();
		geoShopInfo.setId(sysconfigFeign.getUuidByLeaf());
		geoShopInfo.setShopId(shopId);
		geoShopInfo.setGeoCodeLevel1(GeoHashUtils.getGeoHash(lat,lgt,GeoHashConstants.level1));
		geoShopInfo.setGeoCodeLevel2(GeoHashUtils.getGeoHash(lat,lgt,GeoHashConstants.level2));
		geoShopInfo.setGeoCodeLevel3(GeoHashUtils.getGeoHash(lat,lgt,GeoHashConstants.level3));
		geoShopInfo.setGeoCodeLevel4(GeoHashUtils.getGeoHash(lat,lgt,GeoHashConstants.level4));
		geoShopInfo.setGeoCodeLevel5(GeoHashUtils.getGeoHash(lat,lgt,GeoHashConstants.level5));
		geoShopInfo.setGeoCodeLevel6(GeoHashUtils.getGeoHash(lat,lgt,GeoHashConstants.level6));
		geoShopInfo.setGeoCodeLevel7(GeoHashUtils.getGeoHash(lat,lgt,GeoHashConstants.level7));
		geoShopInfo.setGeoCodeLevel8(GeoHashUtils.getGeoHash(lat,lgt,GeoHashConstants.level8));
		geoShopInfo.setGeoCodeLevel9(GeoHashUtils.getGeoHash(lat,lgt,GeoHashConstants.level9));
		geoShopInfo.setGeoCodeLevel10(GeoHashUtils.getGeoHash(lat,lgt,GeoHashConstants.level10));
		geoShopInfo.setGeoCodeLevel11(GeoHashUtils.getGeoHash(lat,lgt,GeoHashConstants.level11));
		geoShopInfo.setGeoCodeLevel12(GeoHashUtils.getGeoHash(lat,lgt,GeoHashConstants.level12));
		geoShopInfoDao.save(geoShopInfo);


    }

}
